home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Source.bin / StatusBar.java < prev    next >
Text File  |  1998-08-21  |  6KB  |  190 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.Color;
  4. import java.awt.BorderLayout;
  5. import java.awt.Label;
  6. import java.awt.LayoutManager;
  7. import java.beans.PropertyVetoException;
  8. import java.beans.PropertyChangeListener;
  9. import java.beans.VetoableChangeListener;
  10. import java.beans.PropertyChangeEvent;
  11.  
  12. // 06/03/97 TGL    Converted to 1.1, added bound/constrained
  13. // 07/18/97 LAB    Made bound and constrained listener registration functions call their super.
  14. //                Cleaned up the code a little.  Addeed version and author tags. Changed
  15. //                incorrect calls to invalidate() to repaint().
  16.  
  17. /**
  18.  * Use a StatusBar to show document status and other information, like the
  19.  * meaning of a button or other user interface element in a window. Typically,
  20.  * a status bar appears at the bottom of a window.
  21.  *
  22.  * @version 1.1, July 18, 1997
  23.  * @author  Symantec
  24.  */
  25. public class StatusBar extends BorderPanel
  26. {
  27.     /**
  28.      * Constructs a default StatusBar.
  29.      * It is constructed with the BEVEL_LINE style.
  30.      */
  31.     public StatusBar()
  32.     {
  33.         super.setLayout(new BorderLayout());
  34.         add("Center", text = new Label());
  35.     }
  36.  
  37.     /**
  38.      * Sets the text that is displayed.
  39.      * @param s the new text to display
  40.      * @see #getStatusText
  41.      * @exception PropertyVetoException
  42.      * if the specified property value is unacceptable
  43.      */
  44.     public void setStatusText(String s) throws PropertyVetoException
  45.     {
  46.         if (! symantec.itools.util.GeneralUtils.objectsEqual(text.getText(), s))
  47.         {
  48.             String oldText = text.getText();
  49.  
  50.             vetos.fireVetoableChange("StatusText", oldText, s);
  51.  
  52.             text.setText(s);
  53.             repaint();
  54.  
  55.             changes.firePropertyChange("StatusText", oldText, s);
  56.         }
  57.     }
  58.  
  59.     /**
  60.      * Gets the text currently displayed.
  61.      * @return the text currently displayed
  62.      * @see #setStatusText
  63.      */
  64.     public String getStatusText()
  65.     {
  66.         return text.getText();
  67.     }
  68.  
  69.     /**
  70.      * Sets the color of the text that is displayed.
  71.      * @param s the new text color
  72.      * @see #getStatusTextColor
  73.      * @exception PropertyVetoException
  74.      * if the specified property value is unacceptable
  75.      */
  76.     public void setStatusTextColor(Color c) throws PropertyVetoException
  77.     {
  78.         if (! symantec.itools.util.GeneralUtils.objectsEqual(textColor, c))
  79.         {
  80.             Color oldColor = textColor;
  81.  
  82.             vetos.fireVetoableChange("StatusTextColor", oldColor, c);
  83.  
  84.             textColor = c;
  85.             text.setForeground(c);
  86.             repaint();
  87.  
  88.             changes.firePropertyChange("StatusTextColor", oldColor, c);
  89.         }
  90.     }
  91.  
  92.     /**
  93.      * Gets the text color currently displayed.
  94.      * @return the current color of displayed text
  95.      * @see #setStatusTextColor
  96.      */
  97.     public Color getStatusTextColor()
  98.     {
  99.         return textColor;
  100.     }
  101.  
  102.     /**
  103.      * Takes no action.
  104.      * This is a standard Java AWT method which gets called to specify
  105.      * which layout manager should be used to layout the components in
  106.      * standard containers.
  107.      *
  108.      * Since layout managers CANNOT BE USED with this container the standard
  109.      * setLayout has been OVERRIDDEN for this container and does nothing.
  110.      *
  111.      * @param l the layout manager to use to layout this container's components
  112.      * (IGNORED)
  113.      * @see java.awt.Container#getLayout
  114.      **/
  115.     public void setLayout(LayoutManager l)
  116.     {
  117.     }
  118.  
  119.     /**
  120.      * Clears the text that gets displayed.
  121.      * @see #setStatusText
  122.      */
  123.     public void clear()
  124.     {
  125.         try
  126.         {
  127.             setStatusText("");
  128.         }
  129.         catch (PropertyVetoException veto) {}
  130.     }
  131.  
  132.     /**
  133.      * Adds a listener for all event changes.
  134.      * @param listener the listener to add.
  135.      * @see #removePropertyChangeListener
  136.      */
  137.     public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
  138.     {
  139.         super.addPropertyChangeListener(listener);
  140.         changes.addPropertyChangeListener(listener);
  141.     }
  142.  
  143.     /**
  144.      * Removes a listener for all event changes.
  145.      * @param listener the listener to remove.
  146.      * @see #addPropertyChangeListener
  147.      */
  148.     public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
  149.     {
  150.         super.removePropertyChangeListener(listener);
  151.         changes.removePropertyChangeListener(listener);
  152.     }
  153.  
  154.     /**
  155.      * Adds a vetoable listener for all event changes.
  156.      * @param listener the listener to add.
  157.      * @see #removeVetoableChangeListener
  158.      */
  159.     public synchronized void addVetoableChangeListener(VetoableChangeListener listener)
  160.     {
  161.         super.addVetoableChangeListener(listener);
  162.         vetos.addVetoableChangeListener(listener);
  163.     }
  164.  
  165.     /**
  166.      * Removes a vetoable listener for all event changes.
  167.      * @param listener the listener to remove.
  168.      * @see #addVetoableChangeListener
  169.      */
  170.     public synchronized void removeVetoableChangeListener(VetoableChangeListener listener)
  171.     {
  172.         super.removeVetoableChangeListener(listener);
  173.         vetos.removeVetoableChangeListener(listener);
  174.     }
  175.  
  176.     /**
  177.      * The text to display.
  178.      */
  179.     protected Label text;
  180.     /**
  181.      * The color of the displayed text.
  182.      */
  183.     protected Color textColor;
  184.  
  185.     // Private members
  186.     private symantec.itools.beans.VetoableChangeSupport vetos = new symantec.itools.beans.VetoableChangeSupport(this);
  187.     private symantec.itools.beans.PropertyChangeSupport changes = new symantec.itools.beans.PropertyChangeSupport(this);
  188. }
  189.  
  190.